package #(package);

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import #(packageBase).model.#(className);
import #(packageBase).form.#(className)Form;
import #(packageBase).param.#(className)QueryParam;
import #(packageBase).common.core.controller.BaseController;
import #(packageBase).business.service.#(className)Service;
import #(packageBase).vo.JsonResult;
import #(packageBase).vo.PageResult;

import java.util.List;

/**
* #(comments) 控制器
*
* @author #(author)
* @date #(datetime)
*/
@Api(value = "#(classname)", tags = "#(comments)相关接口")
@RestController
@RequestMapping("/#(classname)")
public class #(className)Controller extends BaseController {

	@Autowired
	private #(className)Service #(classname)Service;


	@ApiOperation(value = "根据ID查询#(comments)数据")
	@GetMapping(value = {"/{id}"})
	public JsonResult info(@PathVariable #(pk.attrType) #(pk.attrname)) {
		#(className) #(classname) = #(classname)Service.queryObject(#(pk.attrname));
		return JsonResult.ok(#(classname));
	}


	@ApiOperation(value = "分页查询#(comments)列表")
	@GetMapping("/list")
	public PageResult list(@RequestBody #(className)QueryParam #(classname)QueryParam) {
		//分页查询列表数据
		List<#(className)> #(classname)List = #(classname)Service.queryList(#(classname)QueryParam);
		return getPageData(#(classname)List);
	}


	@ApiOperation(value = "新增数据#(comments)数据")
	@PostMapping
	public JsonResult save(@RequestBody #(className)Form #(classname)Form) {
		#(className) #(classname) = #(classname)Form.toPo(#(className).class);
		return #(classname)Service.save(#(classname));
	}


	@ApiOperation(value = "修改#(comments)数据")
	@PutMapping
	public JsonResult update(@RequestBody #(className)Form #(classname)Form){
		#(className) #(classname) = #(classname)Form.toPo(#(className).class);
		return #(classname)Service.save(#(classname));
	}


	@ApiOperation(value = "根据id删除#(comments)数据")
	@DeleteMapping("/{id}")
	public JsonResult delete(@PathVariable #(pk.attrType) #(pk.attrname)){
		return #(classname)Service.delete(#(pk.attrname));
	}


	@ApiOperation(value = "根据ids批量删除#(comments)数据")
	@DeleteMapping("/deleteBatch")
	public JsonResult deleteBatch(<#(pk.attrType)>[] #(pk.attrname)s){
		return #(classname)Service.deleteBatch(#(pk.attrname)s);
	}

}
